/*
 * @Descripttion: 
 * @version: 
 * @Author: ChenXiang
 * @Date: 2021-05-12 22:46:40
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-06-01 16:29:46
 */
import React, { useState } from "react";

export default function App() {
  const [retry, setRetry] = useState(() => () => { });
  const callbackRef = React.useRef(() => alert("init"));
  const callback = callbackRef.current;

  const alert1 = () => {
    alert(1);
  };
  return (
    <div className="App">
      <button onClick={() => (callbackRef.current = () => alert("updated"))}>
        setCallback
      </button>
      <button onClick={callback}>call callback</button>
      <button
        onClick={() => {
          setRetry(() => {
            return 1;
          });
        }}>
        11111111
        </button>
      <button
        onClick={() => {
          setRetry(() => {
            return 2;
          });
        }}>
        222222
        </button>
      <button
        onClick={() => {
          console.log(retry);
        }}
      >
        2222
      </button>
    </div>
  );
}
